package com.dmx.adi;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;


public class Selector {
	
	public static MetadataParser  getMetadataParser(String _xml) {
		try {
			
			Document document = DocumentHelper.parseText(_xml);
			
			Element node = (Element) document.selectSingleNode("//ADI/Metadata/App_Data[@Name='Metadata_Spec_Version']"); 
			
			if (node!=null) {
				if (node.attributeValue("Value").equals(Constants.CableLabsVOD11)) {
					return new VODMetadataParser(_xml);
				}
			}
			
//			return new PegasusMODMetadataParser(_xml);
			
		} catch (Exception e) {
		}
		return null;
	}
	
	public static MetadataParser  getMetadataParser(byte[] _xmlBytes) {
		try {
			
			SAXReader reader = new SAXReader();
			java.io.ByteArrayInputStream in = new java.io.ByteArrayInputStream(_xmlBytes);
			
			Document document = reader.read(in); 
			
			Element node = (Element) document.selectSingleNode("//ADI/Metadata/App_Data[@Name='Metadata_Spec_Version']"); 
			
			if (node!=null) {
				if (node.attributeValue("Value").equals(Constants.CableLabsVOD11)) {
					return new VODMetadataParser(_xmlBytes);
				}
			}
			
//			return new PegasusMODMetadataParser(_xml);
			
		} catch (Exception e) {
		}
		return null;
	}
	
}
